<?php
namespace App\Controller;

use App\Amqp\Producer\ArticleProducer;
use App\Model\Article;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;

use Hyperf\Amqp\Producer;
use Hyperf\Context\ApplicationContext;

#[Controller(prefix:"/api/article")]
class ArticleController extends AbstractController{

    private $producer;

    public function __construct(Producer $producer)
    {
        $this->producer = $producer;
    }
    /**
     * 用户相关设置    
     */
    #[RequestMapping(path: "create", methods: "post")]
    public function create(){ 
        $name = $this->request->input('name');
        $content = $this->request->input('content');

        $ret = Article::create([
            'name'=>$name,
            'content'=>$content,
        ]);

        $message = new ArticleProducer($ret);
        $result = $this->producer->produce($message);

        return $this->response->json([
            'code'=>1,
            'message'=>'成功',
            'data'=>$result
        ]);
    }
}